package com.ruoyi.quartz.service.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.quartz.domain.AttendanceStatistics;
import com.ruoyi.quartz.mapper.SysJobMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

public class TotalTask implements Runnable{

	private String currentDate;
	private SysJobMapper jobMapper;
	private List<AttendanceStatistics> attendanceStatisticsList;

	public TotalTask(List<AttendanceStatistics> attendanceStatisticsList, SysJobMapper jobMapper, String currentDate) {
		this.attendanceStatisticsList = attendanceStatisticsList;
		this.jobMapper = jobMapper;
		this.currentDate = currentDate;
	}

	public TotalTask() {
	}

	public List<AttendanceStatistics> getAttendanceStatisticsList() {
		return attendanceStatisticsList;
	}

	public void setAttendanceStatisticsList(List<AttendanceStatistics> attendanceStatisticsList) {
		this.attendanceStatisticsList = attendanceStatisticsList;
	}

	public String getCurrentDate() {
		return currentDate;
	}

	public void setCurrentDate(String currentDate) {
		this.currentDate = currentDate;
	}

	public SysJobMapper getJobMapper() {
		return jobMapper;
	}

	public void setJobMapper(SysJobMapper jobMapper) {
		this.jobMapper = jobMapper;
	}

	public void run(){
		try {
			System.out.println("共" + attendanceStatisticsList.size() + "条数据");
			List<AttendanceStatistics> list = jobMapper.selectByDate(currentDate);
			if(StringUtils.isEmpty(list)){
				Thread.sleep(3000);
				jobMapper.insertAttendanceStatisticsList(attendanceStatisticsList);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}